package com.xxxx.server.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xxxx.server.mapper.TbackMapper;
import com.xxxx.server.pojo.Admin;
import com.xxxx.server.pojo.RespPageBean;
import com.xxxx.server.pojo.Tback;
import com.xxxx.server.service.ITbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 教职工返校申请 服务实现类
 * </p>
 *
 * @author zhoubin
 * @since 2022-06-02
 */
@Service
public class TbackServiceImpl extends ServiceImpl<TbackMapper, Tback> implements ITbackService {

    @Autowired
    private TbackMapper tbackMapper;

    @Override
    public List<Tback> getTbackByTBId() {
        return tbackMapper.getTbackByTBId(((Admin) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getId());
    }

    @Override
    public RespPageBean getTbackByPage(Integer currentPage, Integer size, Tback tback, String[] beginDateScope) {
        Page<Tback> page = new Page<>(currentPage,size);
        IPage<Tback> TbackByPage = tbackMapper.getTbackByPage(page, tback, beginDateScope);
        RespPageBean respPageBean = new RespPageBean(TbackByPage.getTotal(), TbackByPage.getRecords());
        return respPageBean;
    }

    @Override
    public List<Tback> getTback(Integer id) {
        return tbackMapper.getTback(id);
    }
}
